home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / pdevtest / RCS / pdevtest.c,v < prev    next >
Encoding:
Text File  |  1989-10-24  |  10.6 KB  |  454 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     89.10.24.12.37.53;  author brent;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     88.08.26.16.24.30;  author brent;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     88.04.16.12.27.57;  author brent;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @Top level routine for pseudo-device benchmark
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @Updated to new C library, etc.
  33. @
  34. text
  35. @/*
  36.  * Driver for the new (Dec 87) pseudo-device implementation.
  37.  *
  38.  * The programs output goes to standard out, while the
  39.  * statistics taken go to error output or another file.
  40.  */
  41.  
  42. #include "sprite.h"
  43. #include "status.h"
  44. #include "stdio.h"
  45. #include "fs.h"
  46. #include "fsCmd.h"
  47. #include "sysStats.h"
  48. #include "rpc.h"
  49. #include "proc.h"
  50. #include "vm.h"
  51. #include "kernel/sched.h"
  52. #include "kernel/fsStat.h"
  53. #include "kernel/vm.h"
  54. #include "option.h"
  55.  
  56. Boolean useSelect = FALSE;
  57. Boolean copy = FALSE;
  58. Boolean readP = FALSE;
  59. Boolean writeP = FALSE;
  60. Boolean ioctlP = FALSE;
  61. Boolean selectP = FALSE;
  62. Boolean zero = FALSE;
  63. Boolean switchBuf = FALSE;
  64. Boolean writeBehind = FALSE;
  65. int requestBufSize = 2048;
  66. int size = 128;
  67. int reps = 10;
  68. int numClients = -1;            /* For multi-program synchronization,
  69.                      * this is the number of slaves with
  70.                      * which to synchronize */
  71. int delay = 0;                /* Delay loop for server to eat CPU */
  72. Boolean slave = FALSE;
  73. extern char *pdev;
  74.  
  75. Option optionArray[] = {
  76.     {OPT_INT, "srvr", (Address)&numClients,
  77.         "Server for -srvr (int) clients"},
  78.     {OPT_TRUE, "clnt", (Address)&slave,
  79.         "Client process"},
  80.     {OPT_INT, "reps", (Address)&reps,
  81.         "Number of repetitions"},
  82.     {OPT_INT, "size", (Address)&size,
  83.         "Amount of data to transfer"},
  84.     {OPT_TRUE, "selectTest", (Address)&selectP,
  85.         "Select, makes server block client"},
  86.     {OPT_TRUE, "fork", (Address)©,
  87.         "Fork client process (with -clnt)"},
  88.     {OPT_TRUE, "read", (Address)&readP,
  89.         "Read test"},
  90.     {OPT_TRUE, "write", (Address)&writeP,
  91.         "Write test"},
  92.     {OPT_TRUE, "writeBehind", (Address)&writeBehind,
  93.         "Enable write behind (with -srvr)"},
  94.     {OPT_TRUE, "ioctl", (Address)&ioctlP,
  95.         "IOControl test"},
  96.     {OPT_INT, "delay", (Address)&delay,
  97.         "Loop for -delay <int> cylces before replying"},
  98.     {OPT_TRUE, "switchBuf", (Address)&switchBuf,
  99.         "Test switching request buffers (use with -ioctl)"},
  100.     {OPT_STRING, "pdev", (Address)&pdev,
  101.         "Name of the pseudo device"},
  102.     {OPT_INT, "bufsize", (Address)&requestBufSize,
  103.         "Size of the pseudo device request buffer"},
  104.     {OPT_TRUE, "forceSelect", (Address)&useSelect,
  105.         "Make Master use select with 1 client"},
  106. };
  107. int numOptions = sizeof(optionArray) / sizeof(Option);
  108.  
  109. Time startTime, endTime;
  110. Sched_Instrument startSchedStats, endSchedStats;
  111.  
  112. main(argc, argv)
  113.     int argc;
  114.     char *argv[];
  115. {
  116.     register ReturnStatus status = SUCCESS;
  117.     Proc_PID child;
  118.     Proc_ResUsage usage;
  119.     FILE *outStream;
  120.     register int i;
  121.     ClientData serverData, clientData;
  122.  
  123.     argc = Opt_Parse(argc, argv, optionArray, numOptions);
  124.     if (!slave && (numClients < 0)) {
  125.     fprintf(stderr, "Server: %s [options] -srvr numClients\n",  argv[0]);
  126.     fprintf(stderr, "Client: %s [options] -clnt\n", argv[0]);
  127.     Opt_PrintUsage(argv[0], numOptions, optionArray);
  128.     exit(1);
  129.     }
  130.     /*
  131.      * Check for multi-program master/slave setup.
  132.      */
  133.     if (numClients > 0) {
  134.     ServerSetup(numClients, &serverData);
  135.     slave = FALSE;
  136.     }
  137.     if (slave) {
  138.     ClientSetup(&clientData);
  139.     }
  140.     /*
  141.      * Get first sample of time and idle ticks.
  142.      */
  143.     status = Sys_Stats(SYS_SCHED_STATS, 0, &startSchedStats);
  144.     if (status != SUCCESS) {
  145.     Stat_PrintMsg(status, "Error in Sys_Stats");
  146.     exit(status);
  147.     }
  148.  
  149.     status = Sys_GetTimeOfDay(&startTime, NULL, NULL);
  150.     if (status != SUCCESS) {
  151.     Stat_PrintMsg(status, "Error in Sys_GetTimeOfDay");
  152.     exit(status);
  153.     }
  154.     if (slave) {
  155.     if (copy) {
  156.         status = Proc_Fork(TRUE, &child);
  157.         if (status != PROC_CHILD_PROC && status != SUCCESS) {
  158.         Stat_PrintMsg(status, "Fork failed");
  159.         exit(status);
  160.         }
  161.     }
  162.     if (readP) {
  163.         ClientRead(clientData, size, reps);
  164.     }
  165.     if (writeP) {
  166.         ClientWrite(clientData, size, reps);
  167.     }
  168.     if (ioctlP) {
  169.         ClientIOControl(clientData, size, reps);
  170.     }
  171.     if (copy) {
  172.         if (status != PROC_CHILD_PROC) {
  173.         status = Proc_Wait(0, NULL, TRUE, NULL, NULL, NULL, NULL, &usage);
  174.         } else {
  175.         exit(SUCCESS);
  176.         }
  177.     }
  178.     /*
  179.      * Take ending statistics and print user, system, and elapsed times.
  180.      */
  181.     Sys_GetTimeOfDay(&endTime, NULL, NULL);
  182.     Sys_Stats(SYS_SCHED_STATS, 0, &endSchedStats);
  183.     Time_Subtract(endTime, startTime, &endTime);
  184.     printf("Slave (reps = %d) ", reps);
  185.     PrintTimes(stdout, &usage, &endTime);
  186.  
  187.     ClientDone(clientData);
  188.     /*
  189.      * Print FS statistics.
  190.      */
  191.     } else {
  192.     /*
  193.      * Drop into the top level service loop.  ServeOne is a faster
  194.      * version that doesn't use select because there is only
  195.      * one client.
  196.      */
  197.     if (numClients > 1 || useSelect) {
  198.         Serve(serverData);
  199.     } else {
  200.         ServeOne(serverData);
  201.     }
  202.     /*
  203.      * Take ending statistics and print user, system, and elapsed times.
  204.      */
  205.     Sys_GetTimeOfDay(&endTime, NULL, NULL);
  206.     Sys_Stats(SYS_SCHED_STATS, 0, &endSchedStats);
  207.     Time_Subtract(endTime, startTime, &endTime);
  208.     printf("Master: ");
  209.     PrintTimes(stdout, &usage, &endTime);
  210.  
  211.     if (delay > 0) {
  212.         int cnt;
  213.         Sys_GetTimeOfDay(&startTime, NULL, NULL);
  214.         for (cnt=0 ; cnt<50 ; cnt++) {
  215.         for (i=delay<<1 ; i>0 ; i--) ;
  216.         }
  217.         Sys_GetTimeOfDay(&endTime, NULL, NULL);
  218.         Time_Subtract(endTime, startTime, &endTime);
  219.         Time_Divide(endTime, 50, &endTime);
  220.         printf("%d.%06d seconds service delay\n",
  221.         endTime.seconds, endTime.microseconds);
  222.     }
  223.     }
  224.     exit(status);
  225. }
  226. @
  227.  
  228.  
  229. 1.2
  230. log
  231. @Added service delay
  232. @
  233. text
  234. @d10 1
  235. a10 1
  236. #include "io.h"
  237. a21 3
  238. Boolean flushCache = FALSE;
  239. Boolean clean = FALSE;
  240. Boolean histogram = FALSE;
  241. d24 5
  242. a28 4
  243. Boolean read = FALSE;
  244. Boolean write = FALSE;
  245. Boolean ioctl = FALSE;
  246. Boolean select = FALSE;
  247. d31 1
  248. a38 1
  249. char *outFile = "pdevtest.out";
  250. d42 5
  251. a46 5
  252.     {OPT_INT, 'M', (Address)&numClients,
  253.         "Master for -M (int) clients"},
  254.     {OPT_TRUE, 'S', (Address)&slave,
  255.         "Slave bench program\nTests:"},
  256.     {OPT_INT, 'n', (Address)&reps,
  257. d48 1
  258. a48 1
  259.     {OPT_INT, 'd', (Address)&size,
  260. d50 5
  261. a54 5
  262.     {OPT_TRUE, 's', (Address)&select,
  263.         "Select, makes master block client"},
  264.     {OPT_TRUE, 'c', (Address)©,
  265.         "Copy stream test, the slave forks"},
  266.     {OPT_TRUE, 'r', (Address)&read,
  267. d56 1
  268. a56 1
  269.     {OPT_TRUE, 'w', (Address)&write,
  270. d58 3
  271. a60 3
  272.     {OPT_TRUE, 'W', (Address)&writeBehind,
  273.         "Enable write behind (with -M)"},
  274.     {OPT_TRUE, 'i', (Address)&ioctl,
  275. d62 9
  276. a70 15
  277.     {OPT_INT, 'P', (Address)&delay,
  278.         "Loop for -P <int> cylces before replying"},
  279.     {OPT_TRUE, 'b', (Address)&switchBuf,
  280.         "Test switching request buffers (use with -i)"},
  281.     {OPT_STRING, 'o', (Address)&outFile,
  282.         "Output file name\n"},
  283.     {OPT_STRING, 'p', (Address)&pdev,
  284.         "Name of the master pseudo device\nTracing:"},
  285.     {OPT_TRUE, 'f', (Address)&flushCache,
  286.         "Flush cache before benchmark"},
  287.     {OPT_TRUE, 'x', (Address)&clean,
  288.         "Turn off all tracing"},
  289.     {OPT_TRUE, 'h', (Address)&histogram,
  290.         "Leave histograms on (ok with -x)"},
  291.     {OPT_TRUE, 'z', (Address)&useSelect,
  292. a74 2
  293. FsStats fsStartStats, fsEndStats;
  294. Vm_Stat    vmStartStats, vmEndStats;
  295. d85 1
  296. a85 1
  297.     Io_Stream outStream;
  298. d89 1
  299. a89 1
  300.     Opt_Parse(&argc, argv, numOptions, optionArray);
  301. d91 2
  302. a92 3
  303.     Io_PrintStream(io_StdErr, "Master: %s [-xfpoh] -M numSlaves\n",
  304.                 argv[0]);
  305.     Io_PrintStream(io_StdErr, "Slave: %s [-xfpoh] -S\n", argv[0]);
  306. d94 1
  307. a94 1
  308.     Proc_Exit(1);
  309. a95 51
  310.     if (clean) {
  311.     int newValue;
  312.     newValue = 0;
  313.     Fs_Command(FS_SET_CACHE_DEBUG, sizeof(int), &newValue);
  314.     newValue = 0;
  315.     Fs_Command(FS_SET_TRACING, sizeof(int), &newValue);
  316.     newValue = 0;
  317.     Fs_Command(FS_SET_RPC_DEBUG, sizeof(int), &newValue);
  318.     newValue = 0;
  319.     Fs_Command(FS_SET_RPC_TRACING, sizeof(int), &newValue);
  320.     if (!histogram) {
  321.         newValue = 0;
  322.         (void) Fs_Command(FS_SET_RPC_SERVER_HIST, sizeof(int), &newValue);
  323.         newValue = 0;
  324.         (void) Fs_Command(FS_SET_RPC_CLIENT_HIST, sizeof(int), &newValue);
  325.     }
  326.     }
  327.     if (flushCache) {
  328.     int numLockedBlocks = 0;
  329.     Fs_Command(FS_EMPTY_CACHE, sizeof(int), &numLockedBlocks);
  330.         if (numLockedBlocks > 0) {
  331.             Io_PrintStream(io_StdErr, "Flush found %d locked blocks left\n",
  332.                                       numLockedBlocks);
  333.         }
  334.     }
  335.     outStream = Io_Open(outFile, "w+");
  336.     if (outStream == (Io_Stream)NULL) {
  337.     Io_PrintStream(io_StdErr, "\"%s\": ", outFile);
  338.     Stat_PrintMsg(status, "Can't open");
  339.     Proc_Exit(status);
  340.     }
  341.     /*
  342.      * Copy command line to output file.
  343.      */
  344.     Io_PrintStream(outStream, "%s ", argv[0]);
  345.     if (clean) {
  346.     Io_PrintStream(outStream, "-x ");
  347.     }
  348.     if (histogram) {
  349.     Io_PrintStream(outStream, "-h ");
  350.     }
  351.     if (flushCache) {
  352.     Io_PrintStream(outStream, "-f ");
  353.     }
  354.     if (clean) {
  355.     Io_PrintStream(outStream, "-x ");
  356.     }
  357.     for (i=1 ; i<argc ; i++) {
  358.     Io_PrintStream(outStream, "%s ", argv[i]);
  359.     }
  360.     Io_PrintStream(outStream, "\n");
  361. d107 1
  362. a107 1
  363.      * Get first sample of filesystem stats, vm stats, time, and idle ticks.
  364. a108 10
  365.     status = Fs_Command(FS_RETURN_STATS, sizeof(FsStats), &fsStartStats);
  366.     if (status != SUCCESS) {
  367.     Stat_PrintMsg(status, "Error getting FS stats");
  368.     Proc_Exit(status);
  369.     }
  370.     status = Vm_Cmd(VM_GET_STATS, &vmStartStats);
  371.     if (status != SUCCESS) {
  372.     Stat_PrintMsg(status, "Error getting VM stats");
  373.     Proc_Exit(status);
  374.     }
  375. d112 1
  376. a112 1
  377.     Proc_Exit(status);
  378. d118 1
  379. a118 1
  380.     Proc_Exit(status);
  381. d125 1
  382. a125 1
  383.         Proc_Exit(status);
  384. d128 1
  385. a128 1
  386.     if (read) {
  387. d131 1
  388. a131 1
  389.     if (write) {
  390. d134 1
  391. a134 1
  392.     if (ioctl) {
  393. d141 1
  394. a141 1
  395.         Proc_Exit(SUCCESS);
  396. d150 2
  397. a151 2
  398.     Io_PrintStream(io_StdOut, "Slave: ");
  399.     PrintTimes(io_StdOut, &usage, &endTime);
  400. a152 1
  401.     Sys_Shutdown(0);    /* sync cache */
  402. a153 3
  403.  
  404.     Fs_Command(FS_RETURN_STATS, sizeof(FsStats), &fsEndStats);
  405.     Vm_Cmd(VM_GET_STATS, &vmEndStats);
  406. a156 7
  407.     Io_PrintStream(outStream, "C: ");
  408.     PrintIdleTime(outStream, &startSchedStats, &endSchedStats, &endTime);
  409.     PrintFsStats(outStream, &fsStartStats, &fsEndStats);
  410.     /*
  411.      * Print VM statistics.
  412.      */
  413.     PrintVmStats(outStream, &vmStartStats, &vmEndStats);
  414. d174 2
  415. a175 16
  416.     Io_PrintStream(io_StdOut, "Master: ");
  417.     PrintTimes(io_StdOut, &usage, &endTime);
  418.  
  419.     Sys_Shutdown(0);    /* sync cache */
  420.     Fs_Command(FS_RETURN_STATS, sizeof(FsStats), &fsEndStats);
  421.     Vm_Cmd(VM_GET_STATS, &vmEndStats);
  422.     /*
  423.      * Print FS statistics.
  424.      */
  425.     Io_PrintStream(outStream, "S: ");
  426.     PrintIdleTime(outStream, &startSchedStats, &endSchedStats, &endTime);
  427.     PrintFsStats(outStream, &fsStartStats, &fsEndStats);
  428.     /*
  429.      * Print VM statitistics.
  430.      */
  431.     PrintVmStats(outStream, &vmStartStats, &vmEndStats);
  432. d186 1
  433. a186 1
  434.         Io_PrintStream(io_StdOut, "%d.%06d seconds service delay\n",
  435. d190 1
  436. a190 2
  437.     Io_Flush(outStream);
  438.     Proc_Exit(status);
  439. @
  440.  
  441.  
  442. 1.1
  443. log
  444. @Initial revision
  445. @
  446. text
  447. @d38 1
  448. d64 2
  449. d96 1
  450. a96 1
  451.     int i;
  452. d273 13
  453. @
  454.